package com.jianyun.jyzs.presenter;

import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter;
import com.jianyun.jyzs.dao.AnnCommentDao;
import com.jianyun.jyzs.dao.AnnouncementDao;
import com.jianyun.jyzs.model.AnnounceDetailModel;
import com.jianyun.jyzs.model.imdoel.IAnnounceDetailModel;
import com.jianyun.jyzs.view.iview.IAnnounceDetailView;

import java.util.HashMap;

/**
 * Created by yangshijun on 2018/5/29.
 */

public class AnnoounceDetailPresenter extends MvpBasePresenter<IAnnounceDetailView> {

    /**
     * 获取公告详情
     * @param dao
     * @param newsId
     */
  public   void getAccounceDetailById(AnnouncementDao dao, String newsId){
        if (!isViewAttached()) return;
        getView().showLoading();
        AnnounceDetailModel.getInstance().getAccounceDetailById(dao, newsId, new IAnnounceDetailModel.OnAnnounceDetailListener() {
            @Override
            public void onSuccess() {
                getView().hintLoading();
                getView().onSuccess();
            }

            @Override
            public void onFailed(String msg) {
                getView().hintLoading();
                getView().onFailed(msg);
            }
        });
    }


    /**
     * 提交点赞
     * @param map
     */
    public void commmitLike(HashMap<String, String> map){
        if (!isViewAttached())return;
        getView().showLoading();
        AnnounceDetailModel.getInstance().commmitLike(map, new IAnnounceDetailModel.OnLikeAnnounceListener() {
            @Override
            public void onSuccess() {
                getView().hintLoading();
                getView().onCommitLikeSuccess();
            }

            @Override
            public void onFailed(String msg) {
                getView().hintLoading();
                getView().onFailed(msg);
            }
        });
    }

    /**
     * 提交评论
     * @param map
     */
    public void commitComment(HashMap<String, String> map){
        if (!isViewAttached())return;
        getView().showLoading();
        AnnounceDetailModel.getInstance().commitComment(map, new IAnnounceDetailModel.OnCommentAnnounceListener() {
            @Override
            public void onSuccess() {
                getView().hintLoading();
                getView().onCommitAnnounceSuccess();
            }

            @Override
            public void onFailed(String msg) {
                getView().hintLoading();
                getView().onFailed(msg);
            }
        });
    }


    /**
     * 获取评论
     * @param dao
     * @param map
     * @param enterpriseCode
     */
    public void getAccounceComment(AnnCommentDao dao, HashMap<String, String> map, String enterpriseCode ){

        if (!isViewAttached())return;
        getView().showLoading();
        AnnounceDetailModel.getInstance().getAccounceComment(dao, map, enterpriseCode, new IAnnounceDetailModel.OnGetCommnetAnnounceListener() {
            @Override
            public void onSuccess() {
                getView().hintLoading();
                getView().onSuccess();
            }

            @Override
            public void onFailed(String msg) {
                getView().hintLoading();
                getView().onFailed(msg);
            }
        });
    }


}
